﻿using System;
using System.Collections.Generic;
//using System.Linq;
using System.Web;
using System.Web.Services;
using Microsoft.SharePoint;

namespace WFService
{
    /// <summary>
    /// Summary description for WFAssociation
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class WFAssociation : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld112()
        {
            return "Hello World";
        }

        [WebMethod]
        public string ConfigureList(string strConfigName)
        {
            string SITE_NAME = "http://devsp:7500";
            //  string strConfigName = "";

            #region MyRegion
            
            
            /*
            
            #region MyRegion
            
            

            ///CreateWorkflowConfigurationLists(listName, "http://devsp:7500");

            string strField = string.Empty;
            bool blnAllow = true;
            string strContentType = string.Empty;
            try
            {

                SPListCollection objSPLists = null;
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite sp = new SPSite(SITE_NAME))
                    {
                        using (SPWeb website = sp.OpenWeb())
                        {

                            website.AllowUnsafeUpdates = true;
                            objSPLists = website.Lists;
                            strContentType = strConfigName;
                            foreach (SPList Lst in website.Lists)
                            {
                                // if (Lst.Title == strContentType + "LCN Approval Level" || Lst.Title == strContentType + "Artwork Approval Status" ||Lst.Title ==  strContentType + "Custom Approval Level" )
                                if (Lst.Title == strContentType || Lst.Title == strContentType + "_Status" || Lst.Title == strContentType + "_Custom")
                                {
                                    blnAllow = false;
                                }
                            }
                            // ExceptionHandler.Publish(null, "Step-2", Severity.Informational);
                            SPListTemplateCollection objTemplates = sp.GetCustomListTemplates(website); // website..ListTemplates;

                            //ExceptionHandler.Publish(null, "Step-3", Severity.Informational);
                            // SPList objWFConfigSetting = objSPLists["Workflow Configuration Setting"];


                            if (blnAllow)
                            {
                                foreach (SPListTemplate tmplt in objTemplates)
                                {
                                    Console.WriteLine(tmplt.Name);
                                    if (tmplt.Name.Equals("Approval Level", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        strField = strContentType;
                                        objSPLists.Add(strField, "Approval Level", tmplt);
                                    }
                                    else if (tmplt.Name.Equals("Approval Level_Status", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        strField = strContentType + "_Status";
                                        objSPLists.Add(strField, "Approval Level_Status", tmplt);
                                    }
                                    else if (tmplt.Name.Equals("Approval Level_Custom", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        strField = strContentType + "_Custom";
                                        objSPLists.Add(strField, "Approval Level_Custom", tmplt);
                                    }

                                    //if (tmplt.Name.Equals("LCN Approval Level", StringComparison.CurrentCultureIgnoreCase))
                                    //{
                                    //    strField = strContentType + "LCN Approval Level";
                                    //    objSPLists.Add(strField, "LCN Approval Level", tmplt);
                                    //}
                                    //else if (tmplt.Name.Equals("Artwork Approval Status", StringComparison.CurrentCultureIgnoreCase))
                                    //{
                                    //    strField = strContentType + "Artwork Approval Status";
                                    //    objSPLists.Add(strField, "Artwork Approval Status", tmplt);
                                    //}
                                    //else if (tmplt.Name.Equals("Custom Approval Level", StringComparison.CurrentCultureIgnoreCase))
                                    //{
                                    //    strField = strContentType + "Custom Approval Level";
                                    //    objSPLists.Add(strField, "Custom Approval Level", tmplt);
                                    //}
                                }
                            }

                            //foreach (SPListTemplate tmplt in objTemplates)
                            //{
                            //    //  Console.WriteLine(tmplt.Name);
                            //    if (tmplt.Name.Equals(strLCNApprovalTemplateName, StringComparison.CurrentCultureIgnoreCase))
                            //    {

                            //        strField = strContentType + strLCNApprovalTemplateName;
                            //        blnAllow = true;

                            //        while (i < website.Lists.Count)
                            //        {
                            //            if (website.Lists[i].Title == strField)
                            //            {
                            //                i = website.Lists.Count;
                            //                blnAllow = false;
                            //            }
                            //            i++;
                            //        }
                            //        //foreach (SPList lst in website.Lists)
                            //        //{
                            //        //    if (lst.Title == strField && blnAllow == true)
                            //        //    {
                            //        //        blnAllow = false;
                            //        //        break;
                            //        //    }
                            //        //}
                            //        if (blnAllow)
                            //        {
                            //            objSPLists.Add(strField, strLCNApprovalTemplateName, tmplt);
                            //        }
                            //    }
                            //    if (tmplt.Name.Equals(strApprovalStatusTemplateName, StringComparison.CurrentCultureIgnoreCase))
                            //    {
                            //        strField = strContentType + strApprovalStatusTemplateName;

                            //        if (blnAllow)
                            //        {
                            //            objSPLists.Add(strField, strApprovalStatusTemplateName, tmplt);
                            //        }
                            //    }
                            //    if (tmplt.Name.Equals(strCustomApprovalTemplateName, StringComparison.CurrentCultureIgnoreCase))
                            //    {
                            //        strField = strContentType + strCustomApprovalTemplateName;

                            //        if (blnAllow)
                            //        {
                            //            objSPLists.Add(strField, strCustomApprovalTemplateName, tmplt);
                            //        }
                            //    }
                            //}

                            website.AllowUnsafeUpdates = false;
                            blnAllow = true;
                        }//SPWeb

                    }//SPSite
                });
            }
            catch (Exception Ex)
            {
                // ExceptionHandler.Publish(Ex, "CreateWorkflowConfigurationLists", Severity.Fatal);
                blnAllow = false;
            }
            #endregion
            
            */
            #endregion

            return "Hello World";
        }


      

        //#region METHOD: CreateWorkflowConfigurationLists
        ///// <summary>
        ///// Creates the workflow configuration lists.
        ///// </summary>
        ///// <param name="strConfigName">Name of the configuration list.</param>
        ///// <returns>true/false</returns>
       
        //private bool CreateWorkflowConfigurationLists(string strConfigName, string SITE_NAME)
        //{
        //    string strField = string.Empty;
        //    bool blnAllow = true;
        //    string strContentType = string.Empty;
        //    try
        //    {
              
        //        SPListCollection objSPLists = null;
        //        SPSecurity.RunWithElevatedPrivileges(delegate()
        //        {
        //        using (SPSite sp = new SPSite(SITE_NAME))
        //        {
        //            using (SPWeb website = sp.OpenWeb())
        //            {
                       
        //                    website.AllowUnsafeUpdates = true;
        //                    objSPLists = website.Lists;
        //                    strContentType = strConfigName;
        //                    foreach (SPList Lst in website.Lists)
        //                    {
        //                        // if (Lst.Title == strContentType + "LCN Approval Level" || Lst.Title == strContentType + "Artwork Approval Status" ||Lst.Title ==  strContentType + "Custom Approval Level" )
        //                        if (Lst.Title == strContentType || Lst.Title == strContentType + "_Status" || Lst.Title == strContentType + "_Custom")
        //                        {
        //                            blnAllow = false;
        //                        }
        //                    }
        //                    // ExceptionHandler.Publish(null, "Step-2", Severity.Informational);
        //                    SPListTemplateCollection objTemplates = sp.GetCustomListTemplates(website); // website..ListTemplates;

        //                    //ExceptionHandler.Publish(null, "Step-3", Severity.Informational);
        //                    // SPList objWFConfigSetting = objSPLists["Workflow Configuration Setting"];


        //                    if (blnAllow)
        //                    {
        //                        foreach (SPListTemplate tmplt in objTemplates)
        //                        {
        //                            Console.WriteLine(tmplt.Name);
        //                            if (tmplt.Name.Equals("Approval Level", StringComparison.CurrentCultureIgnoreCase))
        //                            {
        //                                strField = strContentType;
        //                                objSPLists.Add(strField, "Approval Level", tmplt);
        //                            }
        //                            else if (tmplt.Name.Equals("Approval Level_Status", StringComparison.CurrentCultureIgnoreCase))
        //                            {
        //                                strField = strContentType + "_Status";
        //                                objSPLists.Add(strField, "Approval Level_Status", tmplt);
        //                            }
        //                            else if (tmplt.Name.Equals("Approval Level_Custom", StringComparison.CurrentCultureIgnoreCase))
        //                            {
        //                                strField = strContentType + "_Custom";
        //                                objSPLists.Add(strField, "Approval Level_Custom", tmplt);
        //                            }

        //                            //if (tmplt.Name.Equals("LCN Approval Level", StringComparison.CurrentCultureIgnoreCase))
        //                            //{
        //                            //    strField = strContentType + "LCN Approval Level";
        //                            //    objSPLists.Add(strField, "LCN Approval Level", tmplt);
        //                            //}
        //                            //else if (tmplt.Name.Equals("Artwork Approval Status", StringComparison.CurrentCultureIgnoreCase))
        //                            //{
        //                            //    strField = strContentType + "Artwork Approval Status";
        //                            //    objSPLists.Add(strField, "Artwork Approval Status", tmplt);
        //                            //}
        //                            //else if (tmplt.Name.Equals("Custom Approval Level", StringComparison.CurrentCultureIgnoreCase))
        //                            //{
        //                            //    strField = strContentType + "Custom Approval Level";
        //                            //    objSPLists.Add(strField, "Custom Approval Level", tmplt);
        //                            //}
        //                        }
        //                    }

        //                    //foreach (SPListTemplate tmplt in objTemplates)
        //                    //{
        //                    //    //  Console.WriteLine(tmplt.Name);
        //                    //    if (tmplt.Name.Equals(strLCNApprovalTemplateName, StringComparison.CurrentCultureIgnoreCase))
        //                    //    {

        //                    //        strField = strContentType + strLCNApprovalTemplateName;
        //                    //        blnAllow = true;

        //                    //        while (i < website.Lists.Count)
        //                    //        {
        //                    //            if (website.Lists[i].Title == strField)
        //                    //            {
        //                    //                i = website.Lists.Count;
        //                    //                blnAllow = false;
        //                    //            }
        //                    //            i++;
        //                    //        }
        //                    //        //foreach (SPList lst in website.Lists)
        //                    //        //{
        //                    //        //    if (lst.Title == strField && blnAllow == true)
        //                    //        //    {
        //                    //        //        blnAllow = false;
        //                    //        //        break;
        //                    //        //    }
        //                    //        //}
        //                    //        if (blnAllow)
        //                    //        {
        //                    //            objSPLists.Add(strField, strLCNApprovalTemplateName, tmplt);
        //                    //        }
        //                    //    }
        //                    //    if (tmplt.Name.Equals(strApprovalStatusTemplateName, StringComparison.CurrentCultureIgnoreCase))
        //                    //    {
        //                    //        strField = strContentType + strApprovalStatusTemplateName;

        //                    //        if (blnAllow)
        //                    //        {
        //                    //            objSPLists.Add(strField, strApprovalStatusTemplateName, tmplt);
        //                    //        }
        //                    //    }
        //                    //    if (tmplt.Name.Equals(strCustomApprovalTemplateName, StringComparison.CurrentCultureIgnoreCase))
        //                    //    {
        //                    //        strField = strContentType + strCustomApprovalTemplateName;

        //                    //        if (blnAllow)
        //                    //        {
        //                    //            objSPLists.Add(strField, strCustomApprovalTemplateName, tmplt);
        //                    //        }
        //                    //    }
        //                    //}
                      
        //                website.AllowUnsafeUpdates = false;
        //                blnAllow= true;
        //            }//SPWeb

        //        }//SPSite
        //              });
        //    }
        //    catch (Exception Ex)
        //    {
        //        // ExceptionHandler.Publish(Ex, "CreateWorkflowConfigurationLists", Severity.Fatal);
        //        blnAllow= false;
        //    }
        //    return blnAllow;
        //}
        //#endregion



       // */






    }
}
